home *** CD-ROM | disk | FTP | other *** search
- /****************************************************************************/
- /* */
- /* Application: RequiredFinderColors */
- /* */
- /* Description: Under system 7, the finder switches to the black&white */
- /* version of all the desktop icons when certain required */
- /* colors aren't available in the device's color table. */
- /* This snippet shows which colors are needed in the */
- /* system color table for the desktop icons to be */
- /* displayed in their color version. Also with these */
- /* colors, the apple icon in the menu bar will remain in */
- /* color as well. */
- /* */
- /* Files: RequiredFinderColors.π */
- /* RequiredFinderColors.π.rsrc */
- /* RequiredFinderColors.c */
- /* */
- /* Programmer: Edgar Lee */
- /* Organization: Apple Computer, Inc. */
- /* Department: Developer Technical Support, DTS */
- /* Language: C (Think C version 5.0.2) */
- /* Date Created: 09-02-92 */
- /* */
- /****************************************************************************/
-
- /* Constant Declarations */
-
- #define WWIDTH 500
- #define WHEIGHT 100
-
- #define WLEFT (((screenBits.bounds.right - screenBits.bounds.left) - WWIDTH) / 2)
- #define WTOP (((screenBits.bounds.bottom - screenBits.bounds.top) - WHEIGHT) / 2)
-
- void initMac();
- void setUpMenus();
-
- void createWindow();
- void drawWindow();
- void doEventLoop();
-
- main()
- {
- initMac();
- setUpMenus();
-
- createWindow();
-
- doEventLoop();
- }
-
- void initMac()
- {
- MaxApplZone();
-
- InitGraf( &thePort );
- InitFonts();
- InitWindows();
- InitMenus();
- TEInit();
- InitDialogs( nil );
- InitCursor();
- FlushEvents( 0, everyEvent );
- }
-
- void createWindow()
- {
- Rect rect;
- WindowPtr window;
- PaletteHandle palette;
-
- SetRect( &rect, WLEFT, WTOP, WLEFT + WWIDTH, WTOP + WHEIGHT );
- window = NewCWindow( 0L, &rect, "\pRequired Finder Colors", true, documentProc,
- (WindowPtr)-1L, true, 0L );
- SetPort( window );
-
- TextMode( srcXor );
- TextFont( geneva );
- TextSize( 9 );
-
- palette = GetNewPalette( 128 );
- SetPalette( window, palette, true );
- }
-
- void setUpMenus()
- {
- int i;
- Handle menuHandle;
-
- if ((menuHandle = GetNewMBar( 128 )) == nil)
- ExitToShell();
-
- SetMenuBar( menuHandle );
- AddResMenu( GetMenu( 128 ), 'DRVR' );
-
- DrawMenuBar();
- ReleaseResource( menuHandle );
- }
-
- void drawWindow()
- {
- int i;
- int numEntries;
- int lineWidth;
- RGBColor color;
- Str255 string;
-
- numEntries = 10;
- lineWidth = WWIDTH / numEntries;
-
- PenSize( lineWidth, 1 );
-
- for (i = 0; i < numEntries; i++)
- {
- PmForeColor( i );
- MoveTo( i * lineWidth, 0 );
- LineTo( i * lineWidth, WHEIGHT );
-
- Index2Color( i, &color );
-
- MoveTo( i * lineWidth + 5, WHEIGHT * 3 / 8 );
- DrawString( "\pRGB:" );
-
- NumToString( color.red, string );
- MoveTo( i * lineWidth + 5, WHEIGHT / 2 );
- DrawString( string );
-
- NumToString( color.green, string );
- MoveTo( i * lineWidth + 5, WHEIGHT * 5 / 8 );
- DrawString( string );
-
- NumToString( color.blue, string );
- MoveTo( i * lineWidth + 5, WHEIGHT * 6 / 8 );
- DrawString( string );
- }
- }
-
- void doEventLoop()
- {
- EventRecord event;
- WindowPtr window;
- short clickArea;
- Rect screenRect;
-
- for (;;)
- {
- if (WaitNextEvent( everyEvent, &event, 0, nil ))
- {
- if (event.what == mouseDown)
- {
- clickArea = FindWindow( event.where, &window );
-
- if (clickArea == inDrag)
- {
- screenRect = (**GetGrayRgn()).rgnBBox;
- DragWindow( window, event.where, &screenRect );
- }
- else if (clickArea == inContent)
- {
- if (window != FrontWindow())
- SelectWindow( window );
- }
- else if (clickArea == inGoAway)
- if (TrackGoAway( window, event.where ))
- return;
- }
- else if (event.what == updateEvt)
- {
- window = (WindowPtr)event.message;
- SetPort( window );
-
- BeginUpdate( window );
- drawWindow();
- EndUpdate( window );
- }
- }
- }
- }